package com.hdaccp.ch09

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions._
/**
  * 统计男女歌手的比例
  */
object MusicGenderJob {
  //
  def main(args: Array[String]): Unit = {
    //
    val spark = SparkSession.builder()
      .master("local[2]")
      .appName("Ch09MusicGenderJobApp")
      .getOrCreate()
    import  spark.implicits._
    //
    val df = spark.read.format("parquet").load("F:\\accp教学\\sparkresources\\clean13")

    //
    df.createOrReplaceTempView("music")

   // df.sqlContext.sql("select gender,count(1) as times from music group by gender").show()

   // df.select("gender").groupBy("gender").count().show()

    df.select("gender").groupBy("gender").agg(count("gender").as("times"))

    spark.stop()
  }
}
